<div class="page">
	<div class="menu">
		<?php include('modules/members/dashboard.php');?>
    </div>
    <div class="products-list" style="overflow:hidden;">
    	<p style="float:right;" id="button">
        	<a href="#" class="btn" style="font-size:25px;" id="delete_now"><span>ลบที่เลือก</span></a>
       	</p>
	    <p style="float:right;" id="button">
	        <span class="loading"></span>
        	<a href="?m=stickers&p=create" class="btn" style="font-size:25px;" id="order_now"><span>เพิ่มสติกเกอร์</span></a>
       	</p>
    	<table id="products_list" width="100%">
        	<thead>
              <tr>
              	<th width="40">
                <input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);">
               	</th>
            	<th width="40">ID</th>
                <th>ชื่อสินค้า</th>
                <th width="250">รูปภาพ</th>
                <th width="50">ปริ้น</th>
                <th width="60">แก้ไข</th>
                <th width="50">ลบ</th>
              </tr>
            </thead>
            <tbody>
            <?php
            $sql = 'SELECT * FROM products WHERE image_path IS NOT NULL';
			$q = mysql_query($sql);
			while($rs = mysql_fetch_assoc($q)){
			  if($rs['image_path'] != ""){
			?>
              <tr>
              	<td align="center"><input type="checkbox" name="selected[]" value="<?php echo $rs['id'];?>" /></td>
            	<td><?php echo $rs['id'];?></td>
                <td><?php echo $rs['name'];?></td>
                <td align="center"><a href="?m=stickers&p=print&id=<?php echo $rs['id'];?>" style="cursor:pointer;"><img src="stickers/<?php echo $rs['image_path'];?>" width="200"></a></td>
                <td align="center">
                	<a href="?m=stickers&p=print&id=<?php echo $rs['id'];?>" title="สั่งปริ้น">
                		<img src="css/images/Printer.png" width="32"/>
                    </a>
              	</td>
                <td align="center">
                	<a href="?m=stickers&p=create&edit=true&id=<?php echo $rs['id'];?>" title="แก้ไข" id="edit_sticker">
                    	<img src="css/images/edit_32.png" width="20"/>
                    </a>
              	</td>
                <td align="center">
                	<a href="#" title="ลบ" id="delete_sticker">
                    	<img src="css/images/delete.png" width="20"/>
                    </a>
               	</td>
              </tr>
           	<?php 
			  }
			} 
			?>
            </tbody>
        </table>

    </div>
</div>
<script type="text/javascript">
$(function(){
	$('#products_list').dataTable({
		"bJQueryUI": true,
		"sPaginationType": "full_numbers"
	});
	$('#delete_now').click(function(){
		var selected="";
		var i = 0;
		$('#products_list tbody tr td').find('input[type=checkbox]:checked').each(function(){
			if($(this).val() != "on"){
				selected += "&selected["+i+"]="+$(this).val();
			}
			i++;
		});
	  if(selected != ""){
		$.ajax({
			type 	: 'GET',
			url		: 'query.php',
			data	: "delete_selected=true&table=stickers"+selected,
			dataType: 'text',
			success	: function(msg){
				location.reload();
			}
		});
	  }else{
		alert('คุณยังไม่ได้เลือกอะไรเลย');  
	  }
	});
	$('a#delete_sticker').click(function(){
		var id = $(this).closest('tr').find('td:eq(1)').text();
		$.ajax({
			type 	: 'POST',
			url		: 'query.php',
			data	: {delete_sticker:true, id:id},
			dataType: 'text',
			success	: function(msg){
				location.reload();
			}
		});
		return false;
	});
});
</script>
<style type="text/css">
.ui-state-default .ui-icon {
	float:right;
}
</style>